#include <qobject.h>
#include <qstring.h>
#include <qdebug.h>
#include <pluginGl.h>
#include <functional>
#include <qsciscintilla.h>
#include "TerminalPlugin.h"

#define NDD_EXPORTDLL

#if defined(Q_OS_WIN)
#if defined(NDD_EXPORTDLL)
#define NDD_EXPORT __declspec(dllexport)
#else
#define NDD_EXPORT __declspec(dllimport)
#endif
#else
#define NDD_EXPORT __attribute__((visibility("default")))
#endif

#ifdef __cplusplus
extern "C" {
#endif

	NDD_EXPORT bool NDD_PROC_IDENTIFY(NDD_PROC_DATA* pProcData);
	NDD_EXPORT int NDD_PROC_MAIN(QWidget* pNotepad, const QString& strFileName, std::function<QsciScintilla* ()>getCurEdit, NDD_PROC_DATA* procData);


#ifdef __cplusplus
}
#endif

static TerminalPlugin* s_terminalPlugin;

std::function<QsciScintilla* ()> getCurrentEditor;

bool NDD_PROC_IDENTIFY(NDD_PROC_DATA* pProcData)
{
	if (pProcData == NULL){
		return false;
	}

	pProcData->m_strPlugName = QObject::tr("Terminal Plugin");
	pProcData->m_strComment = QObject::tr("A free terminal plugin.");

	pProcData->m_version = QString("v1.2.0.3");
	pProcData->m_auther = QString("CrazyGeeker");

	pProcData->m_menuType = 1;

	return true;
}

int NDD_PROC_MAIN(QWidget* pNotepad, const QString& strFileName, std::function<QsciScintilla*()> getCurEdit, NDD_PROC_DATA* pProcData)
{
	if (!pNotepad || !pProcData)
		return -1;

	getCurrentEditor = getCurEdit;

	if (!s_terminalPlugin)
		s_terminalPlugin = new TerminalPlugin(pNotepad, pProcData->m_rootMenu, strFileName);

	return 0;
}
